package com.example.demo;

import cn.hutool.bloomfilter.BitMapBloomFilter;
import com.example.demo.hutool.BitMap;
import org.apache.lucene.util.RamUsageEstimator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.redis.core.RedisCallback;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import java.util.Set;

@SpringBootApplication
@RestController
public class Demo1Application {
    @Autowired
    RedisTemplate redisTemplate;

    @RequestMapping("/")
  //  @Cacheable(value = "sxmCacheable", key = "'key1'")
    public String sxm() throws InterruptedException {
        Set sxm = redisTemplate.keys("sxm");
//        System.out.println();
//        Properties info = (Properties) redisTemplate.execute((RedisCallback<Object>) connection -> connection.info());
//        Properties commandStats = (Properties) redisTemplate.execute((RedisCallback<Object>) connection -> connection.info("commandstats"));
//        Object dbSize = redisTemplate.execute((RedisCallback<Object>) connection -> connection.dbSize());
//
//        Map<String, Object> result = new HashMap<>(3);
//        result.put("info", info);
//        result.put("dbSize", dbSize);

        BitMap bitMap = new BitMap(1000000);
//        bitMap.setBit(63);
        System.out.println(bitMap.getBit(63));
//        System.out.println(bitMap.getBit(62));

        BitMapBloomFilter filter = new BitMapBloomFilter(60);
        filter.add("123");
        filter.add("abc");
        filter.add("ddd");

// 查找
        System.out.println(filter.contains("abc1"));
        HashMap<Object, Object> objectObjectHashMap = new HashMap<>();

        for (int i = 1; i < 1000000; i++) {
            bitMap.setBit(i);
            objectObjectHashMap.put(i,i);
        }

        System.out.println(bitMap.getBit(100000));
        System.out.println("---");
        //计算指定对象及其引用树上的所有对象的综合大小，单位字节
        long l = RamUsageEstimator.sizeOf(bitMap);
//计算指定对象本身在堆空间的大小，单位字节
        long l1 = RamUsageEstimator.shallowSizeOf(bitMap);
//计算指定对象及其引用树上的所有对象的综合大小，返回可读的结果，如：2KB
        String s = RamUsageEstimator.humanSizeOf(bitMap);
        System.out.println(l);
        System.out.println(l1);
        System.out.println(s);
        l = RamUsageEstimator.sizeOf(objectObjectHashMap);
//计算指定对象本身在堆空间的大小，单位字节
        l1 = RamUsageEstimator.shallowSizeOf(objectObjectHashMap);
//计算指定对象及其引用树上的所有对象的综合大小，返回可读的结果，如：2KB
        s = RamUsageEstimator.humanSizeOf(objectObjectHashMap);
        System.out.println(l);
        System.out.println(l1);
        System.out.println(s);
        Thread.sleep(90000000);
        return "hello";
    }

    public static void main(String[] args) {
        SpringApplication.run(Demo1Application.class, args);
    }

}
